//
//  ACollectionSectionController.m
//  MY_IGList_demo
//
//  Created by mac on 2019/3/25.
//  Copyright © 2019 Yilian. All rights reserved.
//

#import "ACollectionSectionController.h"
#import "ImageCollectionViewCell.h"
#import "GoodsModel.h"
#import "IndexViewController.h"
@interface ACollectionSectionController ()

@property (nonatomic, strong) GoodsModel *goodsModel;

@end

@implementation ACollectionSectionController
- (instancetype)init {
    if (self = [super init]) {
        
        self.inset = UIEdgeInsetsMake(0, 0, 10, 10);
        
    }
    return self;
}

- (NSInteger)numberOfItems{
    return 1;
}
//根据字数多少自适应高度
- (CGSize)sizeForItemAtIndex:(NSInteger)index{
    if (index > 1) {
        return CGSizeMake(self.collectionContext.containerSize.width/3 - 10, self.goodsModel.desc.length + 100);
    }else{
        return CGSizeMake(self.collectionContext.containerSize.width/3 - 10, self.goodsModel.desc.length + 100);
    }
    
}

- (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index{
    ImageCollectionViewCell *cell = [self.collectionContext dequeueReusableCellWithNibName:@"ImageCollectionViewCell" bundle:nil forSectionController:self atIndex:index];
    cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
//    cell.imageViewOfIcon.image = [UIImage imageNamed:@"Image"];
    [cell setCellWithModel:self.goodsModel];
    return cell;
}

- (void)didUpdateToObject:(id)object{
    self.goodsModel = object;
}

- (void)didSelectItemAtIndex:(NSInteger)index{
    NSLog(@"==%ld",index);
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"点击" message:[NSString stringWithFormat:@"%ld",self.section] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self.viewController.navigationController pushViewController:[IndexViewController new] animated:YES];
        
    }];
    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:sure];
    [alert addAction:cancle];
    [self.viewController presentViewController:alert animated:YES completion:nil];
}
@end
